function rankdist = GenRankDist(ccmatrix,flip)

Sheep = diag(ccmatrix);

for i=1:length(Sheep)
    if flip == 1
        rankdist(i) = length(find((ccmatrix(:,i) >= Sheep(i))));
    else
        rankdist(i) = length(find((ccmatrix(i,:) >= Sheep(i))));
    end
end
